package com.winbomb.simulife.impl.choices;

import java.lang.reflect.Constructor;

import android.util.Log;

import com.winbomb.simulife.framework.Game;
import com.winbomb.simulife.framework.Screen;
import com.winbomb.simulife.impl.BaseChoice;

public class ChangeScreenChoice extends BaseChoice {

	Class<?> target;

	public ChangeScreenChoice(String name, Class<?> target) {
		super(name);
		this.target = target;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void doChoice(Game game) {

		try {
			Constructor<Screen> construct = (Constructor<Screen>) target.getConstructor(Game.class);
			Screen targetScreen = construct.newInstance(game);
			game.setScreen(targetScreen);
		} catch (Exception ex) {
			Log.e("", "Failed to switch screen, caused by ", ex);
		}
	}
}
